let express = require("express");
let app = express();
let http = require("http").createServer(app);
let io = require("socket.io")(http);

app.use(express.static("public"));

app.get("/", function(req, res){
    res.sendFile(__dirname + "/index.html");
});

io.on("connection", function(socket){
    console.log("a user connected.");

    socket.on("disconnect", function(){
        console.log("user disconnected.");
    });

    socket.on("chat message", function(msg){
        console.log("message: " + msg);
        io.emit('get message', msg);
    });
});

http.listen(3000, function(){
    console.log("listening on *:3000");
});